﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; 
using DLV.Data.Entities;
using DLV.FrameWork;
using DLV.Library.Utilities;
using System.Data;
namespace DLV.BackEnd.Pages
{
    public partial class AddTours : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        { 
            LoadGroupType();
            LoadTourType(); 
            LoadMartName();
            LoadSeason();
            LoadLandTour();
            if (!String.IsNullOrEmpty(Request.QueryString["Id"]))
            {
                var tour = new TourController().GetTour(int.Parse(Request.QueryString["Id"]));
                ddlTourType.SelectedValue = tour.TourTypeId.ToString();
                ddlLandTour.SelectedValue = tour.HasLandTour.ToString();
                ddlMartName.SelectedValue = tour.MartName;
                ddlSeason.SelectedValue = tour.Season;
                ddlGroupType.SelectedValue =tour.GroupType;
                txtTourName.Text = tour.TourName;
                txtMaTours.Text = tour.MaTour;
                txtnumberofday.Text = tour.QuantityDay.ToString();
                txtnumberofday.Text = tour.QuantityDay.ToString();
                lbGT.Text = tour.TourCity.Split('=')[1];//danh sachs goi tour
                lbCT.Text = tour.TourCity.Split('=')[0];//danh sachs tinhr
            }
            
        } 
        private void LoadTourType()
        {
            ddlTourType.DataSource = new TourTypeController().ListTourType().Where(p => p.Status == (int)Globals.DocumentStatus.Use);
            ddlTourType.DataTextField = "TourTypeName";
            ddlTourType.DataValueField = "TourTypeId";
            ddlTourType.DataBind();

            ddlTourType.Items.Insert(0, new ListItem("--- Chọn loại tour ---", "-1"));
        }
        private void LoadMartName()
        {
            ddlMartName.Items.Insert(0, new ListItem("--- Chọn thị trường ---", "-1"));
            ddlMartName.Items.Insert(1, new ListItem("Inbound", "Inbound"));
            ddlMartName.Items.Insert(2, new ListItem("Outbound", "Outbound"));
            ddlMartName.Items.Insert(3, new ListItem("Nội địa", "Nội địa"));
        }
        private void LoadSeason()
        {
            ddlSeason.Items.Add("Thấp điểm");
            ddlSeason.Items.Add("Cao điểm");
            ddlSeason.Items.Add("Cực cao điểm");

            ddlSeason.Items.Insert(0, new ListItem("---Chọn mùa du lịch---", "-1"));
        }
        private void LoadGroupType()
        {
            var ds = new DataSet();
            ds.ReadXml(MapPath("~/xml/GroupType.xml"));
            var dv = ds.Tables["GroupType"].DefaultView;
            ddlGroupType.DataTextField = "Name";
            ddlGroupType.DataValueField = "ID";
            ddlGroupType.DataSource = dv;
            ddlGroupType.DataBind();
            ddlGroupType.Items.Insert(0, new ListItem("--- Chọn loại hình đoàn ---", "-1"));
        }

        private void LoadLandTour()
        { 
            //ddlLandTour.Items.Insert(0, new ListItem("---Chọn Land Tour---", "-1"));
            //ddlLandTour.Items.Insert(1, new ListItem(" Khong Land Tour ", "1"));
            //ddlLandTour.Items.Insert(2, new ListItem(" Co Land Tour ", "2"));
        }
       
    }
}